/**
 * @Author: Your name
 * @Date:   2021-10-12 10:18:44
 * @Last Modified by:   Your name
 * @Last Modified time: 2021-10-13 14:28:35
 */



// 'use strict';
$(function () { 

    function getUrlParams(url) {
        //1.对url进行处理,把?号后面的参数匹配出来,使用正则进行匹配
        //http://127.0.0.1:5500/detail.html?id=20&age=99
        let reg = /^[^\s]+\?([^&\s\d]+=[^\s]+)*/
        let match = reg.exec(url)
        match = match[1]
        if (!match) {//表示没匹配到
            console.warn("没有匹配到相应的query参数")
            return null
        }
        // console.log(match);
        //对参数进行uri解码
        let queryString = decodeURI(match);
        // console.log(queryString);
        //将queryString以"&"符号为分割点 切割成为一个数组
        let queryArr = queryString.split("&");
        // console.log(queryArr);
        let queryParamsObj = {}//用于存储处理好的query数据
        queryArr.forEach(item => {
            let itemArr = item.split("=") //对每个item 'id=20'这样的切割成['id','20']
            queryParamsObj[itemArr[0]] = itemArr[1]
        })
        // console.log(queryParamsObj);
        //将最终处理的结果返回
        return queryParamsObj
    }
    let qr = getUrlParams(location.href);
         console.log(qr.title);
         
         $('.backupclearfix').html(`<a href="index.html">首页&gt;</a>
         <a href="brand.html">全部分类&gt;</a>
         <a href="brandchild.html">${qr.title}&gt;</a>`)

        $.ajax({
            url: "http://chst.vip:1234/api/getbrandproductlist",
            data:{
                brandtitleid:qr.brandtitleid
            }
            
        }).then(res=>{
            console.log(res);
            render(res.result)
        })


        function render(data=[]) { 
            let html=''
            
            data.forEach(item=>{
                html+=`
                <li>
                    <a href="../pages/brandinformation.html??categoryid=${item.categoryId}&productid=${item.productId}">
                        <div class="left"> ${item.productImg}</div>
                                
                            <div class="right">
                                <div class="top">
                                <h6>${item.productName}</h6>
                                </div>
                                <span class='ddd'>${item.productPrice}</span>
                                <div class="buttom">
                                    <span>${item.productQuote}</span>
                                    <i class="spank">${item.productCom}</i> 
                                </div>
                            </div>
                    </a>
                </li>
                `      
            })
            $('.info').html(html)
         }
    

    



    
 })